home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / mainFrame.php < prev    next >
PHP Script  |  2010-05-19  |  15KB  |  392 lines

  1. <?php
  2. /**
  3.  * mainFrame
  4.  *
  5.  * Display main frame for themes using window (and optionaly icons)
  6.  * Set JS scripts for icons and windows handling
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category   NA
  17.  * @package    NA
  18.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  19.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  20.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version    CVS: $Id:$
  22.  * @link       http://www.weezo.net
  23.  * @since      File available since Release 1.0.0
  24.  */
  25.  
  26. /**
  27.  * @desc Add an icon on main frame
  28.  * @param string $id : icon Id
  29.  * @param string $img : icon's image path
  30.  * @param string $text : icon caption
  31.  * @param string $script : javascript to be executed on click
  32.  * @param string $defaultPosition (optional) : css description of default icon's position
  33.  * @param string $extraHTML (optional) : top div extra HTML
  34.  * @param string $extraStyle (optional) : top div extra style
  35.  * @return string: js array with:
  36.  *             id(0), left(1), top(2), img url(3), icon caption(4), onclick script(5), extraHTML(5), extraStyle(6)
  37. */
  38. function addIcon($id, $img, $text, $script, $defaultPosition=false, $extraHTML=false, $extraStyle=false){
  39.     // Compute position
  40.     $top=-500; $left=-500;
  41.     if(cfGGetVar('activeItems')){
  42.         foreach (cfGGetVar('activeItems') as $value2)
  43.             if($value2['type']=='icon' && $value2['name']=='resIcon_'.$id && $value2['x']!==null && $value2['y']!==null) {
  44.                 $top =$value2['y'];
  45.                 $left=$value2['x'];
  46.             }
  47.     }
  48.     $ico='["'.$id.'",'.$left.','.$top.',"'.addslashes($img).'","'.addslashes(str_replace('>','>',str_replace('<','<',cfUTF8Encode($text)))).'","'.addslashes($script).'","'.addslashes($extraHTML).'","'.addslashes($extraStyle).'"]';
  49.     return $ico;
  50. }
  51.  
  52. /**
  53.  * @desc Insert HTML base code of icons on main frame
  54.  *
  55.  * @param array $resources from which icons are generated
  56.  */
  57. function addIcons($resources){
  58. ?>
  59. <script type="text/javascript">
  60. var iconsList;
  61. (function(){
  62.     var i,o='',u,it=[],f;
  63.     iconsList=[<?php
  64.     $nb=0;
  65.     foreach($resources as $id=>$value)    echo (($nb++)?',':'').addIcon($value['id'],$value['resourceIcon'],$value['name'],$value['resourceJsLink']);
  66.     ?>];
  67. for(i=0;i<iconsList.length;i++) {
  68.     u=iconsList[i];
  69.     o+='<div name="resIcon2" id="resIcon_'+u[0]+'" class="iconDiv" style="left:'+u[1]+'px;top:'+u[2]+'px" onclick="if(!dragCancelOnclick && !menuShown && !W.dd.dragClick) {'+u[5]+'};dragCancelOnclick=false;if(W.event) stopPropagation(event)">';
  70.     o+='<a class="icon" href="javascript:void(0)" title="'+((u[4]).replace(new RegExp('"', 'g'),'\\"'))+'"<?php if(cfGetBrowser()!=='ie') echo ' style="visibility:hidden"';?>>';
  71.     o+='<img src="'+u[3]+'" alt="" id="resIcon_'+u[0]+'_img" onload="fade(this.parentNode)">';
  72.     o+='<span id="iconCaption_'+u[0]+'_cont" class="iconC"></span>';
  73.     o+='<span id="iconCaption_'+u[0]+'" class="iconC hidden">'+u[4]+'</span></a></div>';
  74. }
  75. D.write(o);
  76. })();
  77. </script>
  78. <?php
  79. }
  80.  
  81. /**
  82.  * @desc update active items (windows and background icons) on server from POST data sent from client's mainFrame
  83.  *
  84.  */
  85. function updateActiveItems(){
  86.     $nb=0;
  87.     // get icon data, discard win data
  88.     $opWin=array();
  89.     if(cfGGetVar('activeItems')) foreach (cfGGetVar('activeItems') as $key=>$value) if($value['type']=='icon') $opWin[$key]=$value;
  90.  
  91.  
  92.     /**
  93.      * POST Format :
  94.      * winUpdate => true
  95.      * winActive => HTML id of active window
  96.      *
  97.      * for each windows and icons : X : incremental numeric value
  98.      *
  99.      * icons and windows:
  100.      * name_X => resIcon_6a7a427b01 (resource id)
  101.      * type_X => "icon" or "win"
  102.      * x_X => icon or window x position
  103.      * y_X => icon or window y position
  104.      *
  105.      * windows only:
  106.      * src_X => windows content's URL
  107.      * icon_X => windows icon's HTML code (<img src=...>)
  108.      * reloadable_X => true / false
  109.      * resizable_X => true / false
  110.      * closeable_X => true / false
  111.      * winState_X => normal / max / minMax / minNormal
  112.      */
  113.     while (isset($_POST['name_'.$nb])) {
  114.         // Background icons :
  115.         if($_POST['type_'.$nb]=='icon'){
  116.             $id=substr($_POST['name_'.$nb],strlen('resIcon_'));
  117.         }
  118.         else $id=$nb;
  119.         if(!isset($opWin[$id])) $opWin[$id]=array();
  120.         // Common icons / windows parameters
  121.         $opWin[$id]['name']=$_POST['name_'.$nb];
  122.         $opWin[$id]['type']=$_POST['type_'.$nb];
  123.         $opWin[$id]['x']=$_POST['x_'.$nb];
  124.         $opWin[$id]['y']=$_POST['y_'.$nb];
  125.  
  126.         // Windows specific parameters
  127.         if($opWin[$id]['type']=='win'){
  128.             $opWin[$id]['src']=$_POST['src_'.$nb];
  129.             if(isset($_POST['icon_'.$nb])) $opWin[$id]['icon']=stripcslashes($_POST['icon_'.$nb]);
  130.             $opWin[$id]['capt']=(isset($_POST['capt_'.$nb])) ? html_entity_decode($_POST['capt_'.$nb]): '';
  131.             $opWin[$id]['reloadable']=$_POST['reloadable_'.$nb];
  132.             $opWin[$id]['resizable']=$_POST['resizable_'.$nb];
  133.             $opWin[$id]['closeable']=$_POST['closeable_'.$nb];
  134.             $opWin[$id]['noDrag']=(isset($_POST['noDrag_'.$nb])) ? 'true' : 'false';
  135.             $opWin[$id]['winState']=$_POST['winState_'.$nb];
  136.             $opWin[$id]['w']=$_POST['w_'.$nb];
  137.             $opWin[$id]['h']=$_POST['h_'.$nb];
  138.             if(isset($_POST['winActive']) && $_POST['winActive']==$opWin[$id]['name']) $opWin[$id]['active']=true;
  139.         }
  140.         $nb++;
  141.     }
  142.     cfGSetVar('activeItems',$opWin);
  143.     cfAsyncHeader();
  144.     die(cfAsyncFooter());
  145. }
  146.  
  147. /**
  148.  * Get background Wallpaper and wallpaper position (centered / tiled / streched)
  149.  *
  150.  * @param bool $theme: true to return theme's wallpaper
  151.  * @return array (path to wallpaper, wallpaper type)
  152.  */
  153. function getBackgroundWallpaper($theme=false){
  154.     // User defined wallpaper
  155.     if((!$theme) && WEnv::user()->getVar('accountType')=='singleUser' && ($wp=WEnv::user()->getVar('wallpaper')) && cfBGetVar('name')!='iPhone'){
  156.         if($wp=='no') return array('no',false); // User requested no wallpaper
  157.         // User did not requested theme's default wallpaper
  158.         if($wp!=='theme')
  159.             return array('/gfx/wallpapers/'.$wp,((WEnv::user()->getVar('wallpaperPosition'))?WEnv::user()->getVar('wallpaperPosition'):'centered'));
  160.     }
  161.  
  162.     // List wallpapers located into theme directory
  163.     $wps=glob(cfAppThemeDir(false).'/{wallpaperBoth,themeBoth,wallpaper,theme}-{centered,stretched,tiled}.{jpg,gif,png}',GLOB_BRACE);
  164.     
  165.     if(count($wps)){
  166.         foreach ($wps as $key=>$wp) {
  167.             list($type,$position)=explode('-',cfFileWithoutExtension(basename($wp)));
  168.             $wps[$key]=array('cfn'=>$wp,'type'=>$type,'position'=>$position);
  169.         }
  170.         
  171.         // Look for user-set login wallpaper
  172.         if(!$theme) foreach ($wps as $key=>$wp) if($wp['type']=='wallpaper') return array(cfAppThemeDir(true).'/'.basename($wp['cfn']),$wp['position']);
  173.  
  174.         // Look for user-set login+desktop wallpaper
  175.         if(!$theme) foreach ($wps as $key=>$wp) if($wp['type']=='wallpaperBoth') return array(cfAppThemeDir(true).'/'.basename($wp['cfn']),$wp['position']);
  176.         
  177.         // Look for theme login wallpaper
  178.         foreach ($wps as $key=>$wp) if($wp['type']=='theme') return array(cfAppThemeDir(true).'/'.basename($wp['cfn']),$wp['position']);
  179.  
  180.         // Look for theme login+desktop wallpaper
  181.         foreach ($wps as $key=>$wp) if($wp['type']=='themeBoth') return array(cfAppThemeDir(true).'/'.basename($wp['cfn']),$wp['position']);
  182.     }
  183.  
  184.     return array(false,false);
  185. }
  186.  
  187.  
  188. /**
  189.  * Mobile browsers
  190.  */
  191. if(cfIsMobile('Wii')){
  192.     require(W_THEMES_DIR.'mobile/mainFrame.php');
  193.     exit;
  194. }
  195.  
  196. /**
  197.  * Get wallpaper
  198.  */
  199. require(INCLUDE_DIR.'outputFunctions.php');
  200. require_once(INCLUDE_DIR.'framesFunctions.php');
  201.  
  202. list($wallpaper, $wallpaperPosition )=getBackgroundWallpaper();
  203. list($tWallpaper,$tWallpaperPosition)=getBackgroundWallpaper('theme');
  204. //cfDbg($wallpaper.$wallpaperPosition.' <-> '.$tWallpaper.$tWallpaperPosition);
  205. /*
  206.  ***************************************************************************************************************************
  207.  * Process POST commands
  208.  ***************************************************************************************************************************
  209.  */
  210.  
  211. /*
  212.  * Window / icon position update command
  213.  */
  214. if(isset($_POST['winUpdate'])) updateActiveItems();
  215.  
  216. /*
  217.  * Sticky notes position & edition commands
  218.  */
  219. if(isset($_POST['sNotesAction'])) {
  220.     require_once(INCLUDE_DIR.'stickyNotes.php');
  221.     sNotesUpdate();
  222. }
  223.  
  224. /*
  225.  * Insert HEAD
  226.  */
  227. cfInsertHEAD(false);
  228.  
  229. // Theme specific head data
  230. $mainFrameThemeData=cfTGetVar('mainFrame');
  231. if($mainFrameThemeData['extraHeader']) echo $mainFrameThemeData['extraHeader']."\n";
  232. echo cfScriptLink('win.js');
  233. ?>
  234. <script language="javascript" type="text/javascript">
  235. var winCaptionReload="<?php echo cfCaptionJS('winReload');?>",
  236. winCaptionRestore="<?php echo cfCaptionJS('winRestore');?>",
  237. winCaptionMaximize="<?php echo cfCaptionJS('winMaximize');?>",
  238. winCaptionMinimize="<?php echo cfCaptionJS('winMinimize');?>",
  239. winCaptionTNW="<?php echo cfCaptionJS('musicPopupPlayer');?>",
  240. winCaptionClose="<?php echo cfCaptionJS('winClose');?>",
  241. winCaptionConfig="<?php echo cfCaptionJS('mainConfigButton');?>",
  242. winCaptionLogout="<?php echo cfCaptionJS('genLogout');?>",
  243. winIconConfig="<?php echo outIcon('config3');?>",
  244. winIconLogout="<?php echo outIcon('logout');?>",
  245. windowsAnimation=<?php echo (int)cfHGetVar('windowsAnimation');?>,
  246. winLimitArea=1, isMainFrame=1,
  247. winPadding={'left':0,'top':0,'right':0,'bottom':0},
  248. wallpaper="<?php echo $wallpaper;?>", wallpaperPosition="<?php echo $wallpaperPosition;?>",
  249. tWallpaper="<?php echo $tWallpaper;?>",
  250. tWallpaperPosition="<?php echo $tWallpaperPosition;?>",
  251. desktopColor="<?php if(WEnv::user()->getVar('desktopColor')) echo WEnv::user()->getVar('desktopColor'); else echo '-1'; ?>",
  252. wpImageStretched=new Image(),
  253. scriptLocation="<?php echo $_SERVER['PHP_SELF'];?>",
  254. winConfigBt=function(rId,opt){return '<?php echo (str_replace('<',"<'+'",outButton(cfCaption('genConfigure'),"javascript:void(winIF(\'Win_'+rId+'\').document.location=\\''+opt['remoteConfigFile']+'\\')",outIcon('gears'))));?>';};
  255. <?php
  256. // Menu item(s) padding
  257. if(cfTGetVar('framelessDesktop')){
  258.     $menuPosition=cfTGetVar('menuFrame');
  259.     echo 'winPadding.'.$menuPosition['position'].'='.$menuPosition['size'].";\n";
  260. }
  261.  
  262. // if frameless display, set ping
  263. if(!cfTGetVar('frames')) echo 'var pingInt=setInterval("ping()",'.(max(cfGGetVar('clientPingInterval'),1)*1000).');';
  264.  
  265. if(cfTGetVar('winEmptyHTML')) echo 'winEmptyHTML=\''.str_replace('<','\'+\'<\'+\'',cfTGetVar('winEmptyHTML')).'\';'; else echo 'winEmptyHTML=\'<\'+\'body style="background:white"><\'+\'/body>\';'; // To get a Valid HTML 4.01 Transitional page...
  266. echo "\n";
  267.  
  268. // Set opened windows properties array
  269. echo "var activeItems=[";
  270. if(is_array(cfGGetVar('activeItems'))){
  271.     $nb=0;
  272.     foreach (cfGGetVar('activeItems') as $key=>$value){
  273.         if($value['type']=='win'){
  274.         echo ($nb==0)?'{':',{';
  275.             echo '"name":"'.$value['name'].'"';
  276.             echo ',"type":"'.$value['type'].'"';
  277.             echo ',"x":'.$value['x'].',"y":'.$value['y'];
  278.             if(isset($value['capt'])) echo ',"capt":"'.htmlspecialchars($value['capt']).'"';
  279.             echo ',"src":"'.str_replace('"','\\"',$value['src']).'"';
  280.             if(isset($value['icon'])) echo ',"icon":"'.addslashes($value['icon']).'"';
  281.             echo ',"reloadable":'.$value['reloadable'];
  282.             echo ',"resizable":'.$value['resizable'];
  283.             echo ',"closeable":'.$value['closeable'];
  284.             echo ',"noDrag":'.$value['noDrag'];
  285.             echo ',"winState":"'.$value['winState'].'"';
  286.             echo ',"w":'.$value['w'].',"h":'.$value['h'];
  287.             if(isset($value['active'])) echo ',"active":true';
  288.             echo '}';
  289.             $nb++;
  290.         }
  291.     }
  292. }
  293. echo '];';
  294.  
  295.  
  296. // Restore windows positions and open default or requested resource if appliable
  297. ?>
  298. function bgSetWindows(){
  299.     winRestorePosition(activeItems);
  300.     <?php
  301.     // If client requested a startup resource in login URL GET "res" parameter
  302.     if(WEnv::user()->getVar('displayResourceAtLogin') && (!cfIsMobile('iPhone')||count($_SESSION['res'])==1)){
  303.         echo WEnv::resLinked(WEnv::user()->getVar('displayResourceAtLogin'))->getVar('resourceJsLink').";\n";
  304.         WEnv::user()->setVar('displayResourceAtLogin',false);
  305.     }
  306.     // If account has a single resource, open it
  307.     elseif(!WEnv::config()->getVar('firstPageDisplayed') && (count($_SESSION['res'])==1)) echo $_SESSION['res'][0]['resourceJsLink'].";\n";
  308.  
  309.     WEnv::config()->setVar('firstPageDisplayed',true);
  310.  
  311.     // Hide menu mask if present
  312.     ?>
  313.     if(dd.elements['menuMask']) dd.elements['menuMask'].hide();
  314. }
  315. </script>
  316. <?php
  317.  
  318. /**
  319.  * Insert scripts
  320.  */
  321. echo cfScriptLink('mainFrame.js',true);
  322.  
  323. ?>
  324. </head>
  325.  
  326. <?php
  327.  
  328. /* Body */
  329. echo '<body class="mainFrameBody" onload="bgBodyLoaded()" style="overflow:hidden';
  330.  
  331. // Set background color
  332. if(substr(WEnv::user()->getVar('wallpaper'),0,1)=='-' && WEnv::user()->getVar('accountType')=='singleUser' && cfBGetVar('name')!='iPhone')
  333.     echo ';background-color:#'.substr(WEnv::user()->getVar('wallpaper'),1,6);
  334. elseif(WEnv::user()->getVar('desktopColor') && WEnv::user()->getVar('wallpaper')!='theme' && WEnv::user()->getVar('accountType')=='singleUser' && cfBGetVar('name')!='iPhone')
  335.     echo ';background-color:'.WEnv::user()->getVar('desktopColor');
  336.  
  337. // If wallpaper, remove theme background image not to load it unnecessarily
  338. if($wallpaper && $wallpaper!=='theme') echo ';background-image:none';
  339.  
  340. echo '" ';
  341.  
  342. // Theme extra HTML
  343. if($mainFrameThemeData['bodyExtraHTML']) echo ';'.$mainFrameThemeData['bodyExtraHTML'];
  344. echo ">\n";
  345. // Drag'n drop scripts
  346. echo cfScriptLink('wz_dragdrop.js');
  347. ?>
  348. <script language="javascript" type="text/javascript">;
  349. var disconnectionInProgress=0;
  350. var disconnectionSent=0;
  351. function logout(){
  352.     if(disconnectionInProgress) return;
  353.     disconnectionInProgress=true;
  354.     if(top!=parent.self) document.logoutForm.logout.value="top";
  355.     D.logoutForm.submit();
  356. }
  357. var pingInt = window.setInterval('ping()',pingInterval);
  358. wl.blockBackspace();
  359. </script>
  360. <form name="logoutForm" action="/index.php" target="_parent" enctype="multipart/form-data" method="POST" style="display:none"><input name="logout" value="parent"></form>
  361. <div id="rSPb" class="frame3" style="display:none; position:absolute;left:5px;bottom:5px;"><?php echo cfCaption('menuServerPb');?></div>
  362. <?php
  363.  
  364. // Div covering all desktop
  365. echo '<div id="wpDiv" style="overflow:hidden;height:100%;width:100%;position:absolute;z-index:0"></div>';
  366.  
  367. // Windows "dock" div
  368. echo '<div id="winDock"><div id="winBorder" style="position:absolute;display:none;visibility:hidden"></div></div>';
  369.  
  370. /**
  371.  * Theme background script
  372.  */
  373. if(file_exists(cfAppThemeDir(false).'/background.php')) require_once(W_THEMES_DIR.cfActualTheme().'/background.php');
  374.  
  375. // Register drag items
  376. echo cfDragRegisterItems(false);
  377.  
  378. /**
  379.  * Sticky Notes
  380.  */
  381. if(WEnv::user()->getVar('sNotes')>0 && cfBGetVar('name')!='iPhone'){
  382.     require_once(INCLUDE_DIR.'stickyNotes.php');
  383.     sNotesDisplay();
  384. }
  385.  
  386. // Initialize windows
  387. ?>
  388. <form id="reloadForm" style="display:none" method="POST" action="" target=""><input name="a"><input name="reloadPostData"></form>
  389. <script language="javascript" type="text/javascript">
  390. bgHTMLLoaded();
  391. </script>
  392. </body></html>